package com.example.controller;

import com.example.mapper.MyRepository;
import com.example.service.impl.MyRepositoryImpl;
import com.example.service.impl.MyService;
import com.example.service.impl.MyTianluoService;
import com.example.service.impl2.TianluoServiceInOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@RestController
public class TyyController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private MyTianluoService myTianluoService;
    @Autowired
    private MyService myService;
    @Autowired
    private MyRepository myRepository;
    @Autowired
    private MyRepositoryImpl myRepositoryImpl;

    @Autowired
    private TianluoServiceInOutService tianluoServiceInOutService;

    @RequestMapping(value = "/doSomething")
    public String doSomething(@RequestParam("data") String data){
        tianluoServiceInOutService.doSomething(data);
        return "doSomething!!!";
    }

    @RequestMapping(value = "/save")
    public String save(@RequestParam("data") String data){
        myRepository.save(data+"myRepository");
        myRepositoryImpl.save(data+"myRepositoryImpl");
        myService.doSomething(data+"myService");
        myTianluoService.doSomething(data+"myTianluoService");
        return "index!!!";
    }

    @RequestMapping(value = "/redis/hash/putAll",method = RequestMethod.GET)
    @ResponseBody
    public Map redisTest() {
//        Map以map集合的形式添加键值对
        Map<String, String> maps = new HashMap();
        maps.put("1","星期一");
        maps.put("2","星期二");
        maps.put("3","星期三");
        maps.put("4","星期四");
        redisTemplate.opsForHash().putAll("week", maps);
        return maps;
    }

    @RequestMapping(value = "/redis/hash/get",method = RequestMethod.GET)
    @ResponseBody
    public Object redisTest(@RequestParam String key,@RequestParam String hasKey) {
        Object o = redisTemplate.opsForHash().get(key, hasKey);
        return o;
    }

}
